package 程序员面试金典;

import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

public class WordsFrequency {

    private Map<String, Integer> map = new HashMap<>();
    public WordsFrequency(String[] book) {
        for(String name: book) {
            map.put(name, map.getOrDefault(name, 0) + 1);
        }

    }

    public int get(String word) {
        return map.get(word)==null ? 0 : map.get(word);
    }
}
